package com.shujia.homework;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyReducer extends Reducer<Text, LongWritable,Text,LongWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        long[] count =new long[2];
        values.forEach(e->{
            if(e.get()>=0) {
                count[0] += e.get();
                count[1]++;
            }
        });
        if(count[1]!=0){
            context.write(key,new LongWritable(count[0]/count[1]));
        }

    }
}
